home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / programming / blitzbasic / blitz-list200994.lha / blitz-list / 000303_blitz-list-request_Thu May 12 03:04:49 1994.msg < prev    next >
Internet Message Format  |  1994-09-20  |  7KB

  1. Received: from peladon.rmit.EDU.AU (peladon.rmit.EDU.AU [131.170.1.1]) by kantti.helsinki.fi (8.6.8/8.6.5) with SMTP id DAA26013 for <blitz-list@helsinki.fi>; Thu, 12 May 1994 03:02:38 +0300
  2. Received: from minyos.xx.rmit.EDU.AU by peladon.rmit.EDU.AU with SMTP id AA27599
  3.   (5.65c/IDA-1.4.4 for <blitz-list@helsinki.fi>); Thu, 12 May 1994 10:02:28 +1000
  4. Received: by minyos.xx.rmit.EDU.AU 
  5. From: s924723@minyos.xx.rmit.EDU.AU (Son Huu Le)
  6. Message-Id: <9405120002.19251@minyos.xx.rmit.EDU.AU>
  7. Subject: DeTokenise v2.0
  8. To: blitz-list@helsinki.fi (Blitz List)
  9. Date: Thu, 12 May 1994 10:02:25 +1000 (EST)
  10. X-Mailer: ELM [version 2.4 PL23]
  11. Mime-Version: 1.0
  12. Content-Type: text/plain; charset=US-ASCII
  13. Content-Transfer-Encoding: 7bit
  14. Content-Length: 6297      
  15. X-Status: 
  16. Status: RO
  17.  
  18.  
  19. ;
  20. ; DeTokenise v2.0 by Son Le
  21. ;
  22. ; A program to convert blitz listings into readable text files.
  23. ; Reads blitz2 and deflibs for commands and outputs *.txt text files.
  24. ; Now uses essential routines from ViewLibs. Should work 100%
  25. ;
  26. ; Usage:
  27. ;        DeTokenise file1 file2 ..
  28. ;
  29. ; nb. Blitz doesn't parse quotes ("") properly, so avoid if possible.
  30. ; ps. If this program produces '????' or wrong token names, let me know
  31. ;
  32.  
  33. Macro aligna1
  34.   If ad2&1:ad2+1:EndIf
  35. End Macro
  36.  
  37. Macro skiplibreg
  38.   While Peek.w(ad2):ad2+4:Wend
  39.   ad2+2
  40. End Macro
  41.  
  42. SetErr:NPrint"Fatal error!":End:End SetErr
  43.  
  44. #memsize=16384
  45. #maxtoken=256*256-2           ; Blitz won't allow commands$(65535)=""!?
  46.  
  47. Dim commands$(#maxtoken)
  48.  
  49. error=True:totalcommands.l=0
  50.  
  51. NPrint "DeTokenise v2.0 by Son Le"
  52. NPrint ""
  53. NPrint "Reading blitz2 commands.."
  54. If Exists("blitz2:blitz2")
  55.   If ReadFile(0,"blitz2:blitz2")
  56.     size.l=Lof(0)
  57.     memblock.l=AllocMem(size,1)
  58.     If memblock<>0
  59.       memuse.l=memblock
  60.       ReadMem 0,memblock,size
  61.       Repeat:memuse+2:Until Peek.w(memuse)=$3f3
  62.       Repeat:memuse+2:Until Peek.w(memuse)=$3f2
  63.       For i.w=1 To $d3
  64.         If i=$b6 Then i+1  ; command $80b6 doesn't exist!?
  65.         If memuse&1 Then memuse+1
  66.         Repeat:memuse+2:Until Peek.w(memuse)=i
  67.         memuse+2:command$=Peek$(memuse)
  68.         token.l=$8000|i:commands$(token)=command$
  69.         totalcommands+1
  70.         memuse+Len(command$)+1
  71.         memuse+Len(Peek$(memuse))+1
  72.       Next
  73.       CloseFile 0
  74.       FreeMem memblock,size
  75.       error=False
  76.     Else
  77.       NPrint "Cannot allocate memory!"
  78.     EndIf
  79.   EndIf
  80. Else
  81.   NPrint "Cannot find 'blitz2'?! Please check 'blitz2:' assignment!"
  82. EndIf
  83.  
  84. If error=True Then End
  85. SetSignal_ 0,$1000      ; clear CTRL-C signal
  86.  
  87. numoflibs.l=0
  88. NPrint "Reading deflibs commands.."
  89. If Exists("blitz2:deflibs")
  90.   mem.l=AllocMem(#memsize,1)
  91.   If mem<>0
  92.     If ReadFile(0,"blitz2:deflibs")
  93.       Repeat
  94.         ReadMem 0,mem,8            ; get library size and $3f3
  95.         If Peek.l(mem+4)=$3f3      ; start of hunk?
  96.           libsize.l=Peek.l(mem)
  97.           If libsize>#memsize
  98.             memuse.l=AllocMem(libsize,1):memfree=True
  99.             If memuse=0
  100.               NPrint "Cannot allocate ",libsize," bytes of memory!"
  101.               CloseFile 0:FreeMem mem,#memsize
  102.               End
  103.             EndIf
  104.           Else
  105.             memuse.l=mem:memfree=False
  106.           EndIf
  107.           ReadMem 0,memuse,libsize-4    ; get library
  108.           libnum.l=Peek.w(memuse+32)&$ffff
  109.           lib.l=(Int(libnum/2)+$80)&$ff
  110.           ad2.l=memuse+28+48
  111.           If libnum<256
  112.             numoflibs+1
  113.             Print Chr$(13)+"Processing library: #",libnum,"  "
  114.             If libnum&1 Then commandnum.w=$80 Else commandnum.w=$0
  115.             If SetSignal_(0,0)&$1000    ; check for CTRL-C
  116.               If memfree Then FreeMem memuse,libsize
  117.               CloseFile 0:FreeMem mem,#memsize
  118.               NPrint ""
  119.               NPrint "*** Break: DeTokenise"
  120.               End
  121.             EndIf
  122.  
  123.             ; following code is taken from ViewLibs with minor modifications
  124.  
  125.             loop2
  126.             d0.l=Peek.w(ad2)
  127.             If d0>=0
  128.               commandnum+1
  129.               ad2+6:If d0=8 Then Goto addtoke
  130.               If d0&15
  131.                 If d0&4
  132.                   ad2+4:While Peek.b(ad2)>=0:ad2+1:Wend
  133.                   ad2+1:!aligna1:Goto addtoke
  134.                 Else
  135.                   Goto stloop
  136.                 EndIf
  137.               EndIf
  138.               ;
  139.               !skiplibreg:ad2+12:Goto loop2
  140.               ;
  141.               stloop
  142.               d0=Peek.w(ad2):ad2+2:If d0<0 Then Goto addtoke
  143.               ad2+(d0&255):!aligna1:!skiplibreg:ad2+12:Goto stloop
  144.               ;
  145.               addtoke
  146.               ad2+6:co$=Peek$(ad2):ad2+Len(co$)+1
  147.               ad2+Len(Peek$(ad2))+1:!aligna1
  148.               token=(lib LSL8)|commandnum:commands$(token)=co$
  149.               totalcommands+1
  150.               ;
  151.               Goto loop2
  152.             EndIf
  153.           EndIf
  154.         Else
  155.           If NOT Eof(0)
  156.             If memfree Then FreeMem memuse,libsize
  157.             CloseFile 0:FreeMem mem,#memsize
  158.             NPrint ""
  159.             NPrint "Corrupt 'deflibs' structure?!"
  160.             End
  161.           EndIf
  162.         EndIf
  163.         If memfree Then FreeMem memuse,libsize
  164.       Until Eof(0)
  165.       CloseFile 0:FreeMem mem,#memsize
  166.       NPrint ""
  167.     EndIf
  168.   Else
  169.     NPrint "Cannot allocate memory!"
  170.   EndIf
  171. Else
  172.   NPrint "Cannot find 'deflibs'?!"
  173. EndIf
  174.  
  175. NPrint "Total scanned libraries : ",numoflibs
  176. NPrint "Total number of commands: ",totalcommands
  177.  
  178. DosBuffLen 16384
  179. For a=1 To NumPars
  180.   If Par$(a)<>""
  181.     NPrint ""
  182.     NPrint "DeTokenising '",Par$(a),"'"
  183.     If Exists(Par$(a))
  184.       If ReadFile(0,Par$(a))
  185.         size=Lof(0)
  186.         progmem.l=AllocMem(size,1)
  187.         memuse=progmem
  188.         If progmem<>0
  189.           ReadMem 0,progmem,size:CloseFile 0
  190.           If WriteFile(0,Par$(a)+".txt")
  191.             FileOutput 0
  192.             Repeat
  193.               char.b=Peek.b(memuse)
  194.               If char=0
  195.                 NPrint ""
  196.               Else
  197.                 If (char&$80)
  198.                   Gosub checkprogress
  199.                   token=((char LSL8)|(Peek.b(memuse)&$ff))&$ffff
  200.                   If commands$(token)="" OR token>#maxtoken
  201.                     Print "????"
  202.                   Else
  203.                     Print commands$(token)
  204.                   EndIf
  205.                 Else
  206.                   Print Chr$(char)
  207.                 EndIf
  208.               EndIf
  209.               _next
  210.               Gosub checkprogress
  211.             Until memuse=progmem+size
  212.             CloseFile 0:FreeMem progmem,size:DefaultOutput
  213.             NPrint Chr$(13),"working  ( ",size," / ",size," )"
  214.             NPrint "Done!"
  215.           Else
  216.             NPrint "Cannot open output file ",Par$(a),".txt!"
  217.           EndIf
  218.         Else
  219.           CloseFile 0
  220.           NPrint "Cannot allocate memory!"
  221.         EndIf
  222.       EndIf
  223.     Else
  224.       NPrint "Cannot find ",Par$(a),"!"
  225.     EndIf
  226.   EndIf
  227. Next
  228.  
  229. End
  230.  
  231. checkprogress:
  232. memuse+1:progress.l=memuse-progmem
  233. If (progress MOD 1024)=0
  234.   DefaultOutput
  235.   Print Chr$(13)+"working  ( ",progress," / ",size," )"
  236.   FileOutput 0
  237. EndIf
  238. Return
  239.  
  240.  
  241. -- 
  242. Son H. Le                             email: s924723@minyos.xx.rmit.edu.au
  243. "A spoonful of sugar helps the medicine go down.. in the most delightful way"